#include <stdio.h>
#include <stdlib.h>
#include "linkList.h"

int *reverseBookList(struct linkList *head, int size)
{
    struct linkList *temp_1 = head;
    struct linkList *temp_2 = head;
    while (temp_1 != NULL)
    {
        size++;
        temp_1 = temp_1->next;
    }
    int *stack = (int *)malloc(size * sizeof(int));
    int top = -1;
    while (temp_2 != NULL)
    {
        top++;
        stack[top] = temp_2->val;
        temp_2 = temp_2->next;
    }
    int *res = (int *)malloc(size * sizeof(int));
    for (int i = 0; i < size; i++)
    {
        res[i] = stack[top];
        top--;
    }
    return res;
}

void init(struct linkList *list)
{
    list->next = NULL;
    list->val = 0;
}

int createList(struct linkList *list)
{
    int input = 0;
    int size = 0;
    while (1)
    {
        printf("please input number :\n");
        scanf("%d", &input);
        if (input == -1)
            break;
        struct linkList *node = (struct linkList *)malloc(sizeof(struct linkList));
        init(node);
        node->val = input;
        list->next = node;
        list = list->next;
        size++;
    }
    return size;
}

int main()
{
    struct linkList *list = (struct linkList *)malloc(sizeof(struct linkList));
    init(list);
    int size = createList(list);
    int *res = reverseBookList(list, size);
    for (int i = 0; i < size; i++)
    {
        printf("%d", res[i]);
    }
    getchar();
    return 0;
}
